package com.zls.controller;

import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.page.Result;
import com.zls.pojo.Branch;
import com.zls.service.BranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/branch")
public class BranchController {
    @Autowired
    private BranchService branchService;
    @GetMapping("findAll")
    public List<Branch> findAll(){
        List<Branch> all = branchService.findAll();
        return all;
    }

    /**
     * 工程阶段列表查询
     */
    @PostMapping("all")
    public PageResult all(@RequestBody QueryPageBean queryPageBean){
        PageResult page = branchService.findPage(queryPageBean);
        return page;
    }
    /**
     * 工程阶段列表添加
     */
    @PostMapping("add")
    public Result add(@RequestBody Branch branch){
        int i = branchService.addBranch(branch);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
    /**
     * 查询修改工程阶段列表
     */
    @GetMapping("findByBid")
    public Result findById(@RequestParam("bid") String  bid){
        Branch branch=branchService.findByBid(bid);
        Result result=new Result();
        if (branch!=null){
            result.setData(branch);
            result.setFlag(true);
        }else {
            result.setMessage("系统错误");
        }
        return result;
    }
    /**
     * 修改工程列表
     */
    @PostMapping("edit")
    public Result edit(@RequestBody Branch branch){
        int i = branchService.editBranch(branch);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
    /**
     * 工程阶段列表删除
     */
    @GetMapping("delete")
    public Result delete(@RequestParam("bid")String bid){
        int i = branchService.deleteBranch(bid);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
}
